import "babel-polyfill" //这个一定要放在第一行
import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

import VueSocketio from 'vue-socket.io';
// import VueSocketio from '@/vue-socketio' //引入路径根据实际项目情况而定，这里只是参考
import socketio from 'socket.io-client';

import comment from './api/comment'
console.log(comment)
Vue.prototype.$comment = comment
console.log(Vue)
// 引入echarts
import echarts from 'echarts'
Vue.prototype.$echarts = echarts

Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

Vue.config.productionTip = false

try {
  // const SocketInstance = socketio.connect('http://3.226.17.158:3000', {
  const SocketInstance = socketio.connect(process.env.VUE_APP_BASE_SOCKET_PORT, {
  // const SocketInstance = socketio.connect(process.env.SOCKET_PORT || 'http://localhost:3000', {
    // query: {
    //   token: window.localStorage.getItem('token')
    // }
  });
  Vue.use(new VueSocketio({
    debug: true,
    connection: SocketInstance
  }));
} catch (error) {
  // debugger
}

var royapp = new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App),
})

String.prototype.allReplace = function (f, e) { //吧f替换成e
  var reg = new RegExp(f, "g"); //创建正则RegExp对象   
  return this.replace(reg, e);
}
Date.prototype.FormatCopy = function (fmt) { //author: meizz 
  var o = {
    "M+": this.getMonth(), //月份 
    "d+": this.getDate(), //日 
    "h+": this.getHours(), //小时 
    "m+": this.getMinutes(), //分 
    "s+": this.getSeconds(), //秒 
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
    "S": this.getMilliseconds() //毫秒 
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) :
      (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}
Date.prototype.Format = function (fmt) { //author: meizz 
  var o = {
    "M+": this.getMonth() + 1, //月份 
    "d+": this.getDate(), //日 
    "h+": this.getHours(), //小时 
    "m+": this.getMinutes(), //分 
    "s+": this.getSeconds(), //秒 
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
    "S": this.getMilliseconds() //毫秒 
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) :
      (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}